/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaclientcp3110.View.Component;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import common.Objects.Category;
import common.Objects.Component;
import javaclientcp3110.Model.Component.CompDeleteModel;
import javaclientcp3110.Model.MainModel;
import common.UCM.UC2AL;
import javaclientcp3110.UCM.UCDeleteComponent;
import javax.swing.JOptionPane;

/*
 * CompDeleteView.java
 *
 * Created on 14/08/2009, 4:14:48 PM
 * @author Richard Irons
 */
public class CompDeleteView extends javax.swing.JPanel {

    private CompDeleteModel model;
    /** Creates new form CompDeleteView */
    public CompDeleteView() {
        this(new CompDeleteModel());
    }

    public CompDeleteView(CompDeleteModel model) {
        this.model = model;
        
        initComponents();
        compDeleteButton.addActionListener(new UC2AL(new UCDeleteComponent(this, model)));

        Category currentItem = (Category)compCatagoryComboBox.getSelectedItem();
        componentComboBox.populateComboBox_viaCategory(currentItem.getId());
        compCatagoryComboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                Category currentCategory = (Category) e.getItem();
                componentComboBox.populateComboBox_viaCategory(currentCategory.getId());
            }
        });
    }
    public Component getComponent() {
        return (Component) componentComboBox.getSelectedItem();
    }
    public void updateComponentList() {
        Category currentCategory = (Category) compCatagoryComboBox.getSelectedItem();
        componentComboBox.populateComboBox_viaCategory(currentCategory.getId());
    }
    public void errorMessage(String message) {
        JOptionPane.showMessageDialog(null,
            message,
            "Error",
            JOptionPane.ERROR_MESSAGE);
    }
    public void successMessage(String message) {
        JOptionPane.showMessageDialog(null,
            message,
            "Success!",
            JOptionPane.INFORMATION_MESSAGE);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        compDeleteButton = new javax.swing.JButton();
        titleLabel = new javax.swing.JLabel();
        compCatagoryLabel = new javax.swing.JLabel();
        compComponentLabel = new javax.swing.JLabel();
        compCatagoryComboBox = new javaclientcp3110.View.Component.CategoryListView(MainModel.getInstance().getCategorys());
        componentComboBox = new javaclientcp3110.View.Component.ComponentListView();

        setMaximumSize(new java.awt.Dimension(500, 400));
        setMinimumSize(new java.awt.Dimension(500, 400));

        compDeleteButton.setText("Delete Component");
        compDeleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                compDeleteButtonActionPerformed(evt);
            }
        });

        titleLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        titleLabel.setText("Select a component to delete");

        compCatagoryLabel.setText("Catagory:");

        compComponentLabel.setText("Component:");

        compCatagoryComboBox.setMaximumSize(new java.awt.Dimension(28, 20));

        componentComboBox.setMaximumSize(new java.awt.Dimension(28, 20));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(109, 109, 109)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(compDeleteButton)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(compCatagoryLabel)
                            .addComponent(compComponentLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(titleLabel)
                            .addComponent(compCatagoryComboBox, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                            .addComponent(componentComboBox, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))))
                .addGap(147, 147, 147))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(111, 111, 111)
                .addComponent(titleLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(compCatagoryLabel)
                    .addComponent(compCatagoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(compComponentLabel)
                    .addComponent(componentComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(compDeleteButton)
                .addContainerGap(179, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void compDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_compDeleteButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_compDeleteButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javaclientcp3110.View.Component.CategoryListView compCatagoryComboBox;
    private javax.swing.JLabel compCatagoryLabel;
    private javax.swing.JLabel compComponentLabel;
    private javax.swing.JButton compDeleteButton;
    private javaclientcp3110.View.Component.ComponentListView componentComboBox;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables

}
